/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-20
*/
package com.rzico.order.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;

/**
 * <pre>
 *   采购单数据库对象
 * </pre>
 * @author Rzico Boot
 * @version 1.0
 */
@Data
@Table(name = "wx_purchase_item")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PurchaseItem{
    @Id
    @ApiModelProperty(value = "" )
    protected Long id;

    @ApiModelProperty(value = "创建日期", hidden = true)
    protected java.util.Date createDate;

    @ApiModelProperty(value = "修改日期", hidden = true )
    protected java.util.Date modifyDate;

    @ApiModelProperty(value = "成本价" )
    protected java.math.BigDecimal cost;

    @ApiModelProperty(value = "商品名称" )
    protected String name;

    @ApiModelProperty(value = "采购价" )
    protected java.math.BigDecimal price;

    @ApiModelProperty(value = "数量" )
    protected BigDecimal quantity;

    @ApiModelProperty(value = "已退货数量" )
    protected BigDecimal returnQuantity;

    @ApiModelProperty(value = "已入库数量" )
    protected BigDecimal stockQuantity;

    @ApiModelProperty(value = "商品编号" )
    protected String sn;

    @ApiModelProperty(value = "商品规格" )
    protected String spec;

    @ApiModelProperty(value = "单位")
    protected String unit;

    @ApiModelProperty(value = "商品重量")
    protected java.math.BigDecimal weight;

    @ApiModelProperty(value = "商品规格" )
    protected String thumbnail;

    @ApiModelProperty(value = "商品ID" )
    protected Long productId;

    @ApiModelProperty(value = "采购单" )
    protected Long purchaseId;

    @ApiModelProperty(value = "优惠折扣金额" )
    protected java.math.BigDecimal discount;

    @ApiModelProperty(value = "可入库数量")
    public BigDecimal getAvailableStockQuantity() {
        if (getStockQuantity()==null) {
            setStockQuantity(BigDecimal.ZERO);
        }
        if (getReturnQuantity()==null) {
            setReturnQuantity(BigDecimal.ZERO);
        }
        if (getQuantity()==null) {
            setQuantity(BigDecimal.ZERO);
        }
        return getQuantity().subtract(getStockQuantity()); //.subtract(getReturnQuantity());
    }

    @ApiModelProperty(value = "可退货数量")
    public BigDecimal getAvailableReturnQuantity() {
        if (getStockQuantity()==null) {
            setStockQuantity(BigDecimal.ZERO);
        }
        if (getReturnQuantity()==null) {
            setReturnQuantity(BigDecimal.ZERO);
        }
        if (getQuantity()==null) {
            setQuantity(BigDecimal.ZERO);
        }
        return getQuantity().subtract(getReturnQuantity());
    }

    public void setAvailableStockQuantity(BigDecimal value) {

    }

    public void setAvailableReturnQuantity(BigDecimal value) {

    }

    @ApiModelProperty(value = "商品金额")
    public BigDecimal getAmount(){
        return this.getPrice().multiply(this.getQuantity()).setScale(2,BigDecimal.ROUND_HALF_DOWN);
    }

    @ApiModelProperty(value = "实收金额")
    public BigDecimal getSubTotal(){
        if (getDiscount()==null) {
            setDiscount(BigDecimal.ZERO);
        }
        return this.getPrice().multiply(this.getQuantity()).subtract(getDiscount()).setScale(2,BigDecimal.ROUND_HALF_DOWN);
    }


    public void setAmount(BigDecimal value) {

    }

    public void setSubTotal(BigDecimal value) {

    }
}
